#include <stdio.h>

#define		SRC_LEN1		4
#define		SRC_LEN2		4
#define		SRC_LEN3		8

char		*pSrc1 = "abcd";
char		*pSrc3 = "23456789";
char		pDst1[5] = {0, };
char		pDst3[9] = {0, };
char        nTmpRefChar[8][2][4] = {{{'3', '0', '0', '0'}, {'a', 'b', 'c', '0'}},
									{{'3', '0', '0', '0'}, {'d', 'e', 'f', '0'}},
									{{'3', '0', '0', '0'}, {'g', 'h', 'i', '0'}},
									{{'3', '0', '0', '0'}, {'j', 'k', 'l', '0'}},
									{{'3', '0', '0', '0'}, {'m', 'n', 'o', '0'}},
									{{'4', '0', '0', '0'}, {'p', 'q', 'r', 's'}},
									{{'3', '0', '0', '0'}, {'t', 'u', 'v', '0'}},
									{{'4', '0', '0', '0'}, {'w', 'x', 'y', 'z'}}};

char        (*pRefChar)[8][2][4] = &(nTmpRefChar);

void Prob1(char *pSrc, char *pDst, int *pUsed, int nLen, int nLevel);
void Prob2(char *pSrc, char *pDst, int nLen, int nStart, int nLevel);
void Prob3(char *pSrc, char *pDst, char (*pRefChar)[8][2][4], int nNumLen, int nLevel);


void main(void)
{
	int   pUsed[4] ={0, };

    //Prob1(pSrc1, &(pDst1[0]), &(pUsed[0]), SRC_LEN1, 0);
	//Prob2(pSrc1, &(pDst1[0]), SRC_LEN1, 0, 0);
	Prob3(pSrc3, pDst3, pRefChar, SRC_LEN3, 0);

	return;
}


void Prob1(char *pSrc, char *pDst, int *pUsed, int nLen, int nLevel)
{
    int    i = 0;

    if(nLen == nLevel)
	{
        printf("%s\n", pDst);
		return;
	}

    for(i=0 ; i<nLen ; i++)
    {
        if(1 == pUsed[i])
            continue;

		pDst[nLevel] = pSrc[i];
        pUsed[i] = 1;

        Prob1(pSrc, pDst, pUsed, nLen, nLevel+1);

        pUsed[i] = 0;
    }

	return;
}

void Prob2(char *pSrc, char *pDst, int nLen, int nStart, int nLevel)
{
	int  nCount = 0;
	
    for(nCount=nStart ; nCount<nLen ; nCount++)
    {
	    pDst[nLevel] = pSrc[nCount];
		printf("%s\n", pDst);
	
		Prob2(pSrc, pDst, nLen, nCount+1, nLevel+1);
		
		pDst[nLevel] = '\0';
    }
}

int nTotalLoop = 0;

void Prob3(char *pSrc, char *pDst, char (*pRefChar)[8][2][4], int nNumLen, int nLevel)
{
    int   nCount = 0;

    if(nLevel == nNumLen)
    {
		printf("%-8d% - s\n", nTotalLoop++, pDst);
		return;
	}

    for(nCount=0 ; nCount<((*pRefChar)[(pSrc[nLevel]-48 - 2)][0][0]-48) ; nCount++)
    {
		pDst[nLevel] = (*pRefChar)[(pSrc[nLevel]-48 - 2)][1][nCount];

        Prob3(pSrc, pDst, pRefChar, nNumLen, nLevel+1);
    }
}
